import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:xvideos/hj_model/message/search_user_obj.dart';
import 'package:xvideos/hj_utils/api_service/vid_service.dart';
import 'package:xvideos/tools_base/debug_log.dart';

class HotUpListLogic extends GetxController {
  HotUpListLogic();

  RefreshController? refreshController;
  int pageNumber = 1;
  bool isLoading = true;
  List<HotBloggerEntity> dataSource = [];

  @override
  void onReady() {
    super.onReady();
    fetchPagedata();
  }

  @override
  void onInit() {
    super.onInit();
  }

  void loadMoreData() {
    fetchPagedata(page: pageNumber + 1);
  }

  fetchPagedata({int page = 1, int size = 16}) async {
    try {
      var resp = await VidService.fetchUpList(page, size);
      pageNumber = page;
      if (page == 1) {
        dataSource.clear();
      }
      if (resp?.hasNext ?? false) {
        refreshController?.loadComplete();
      } else {
        refreshController?.loadNoData();
      }
      dataSource.addAll(resp?.list ?? []);
    } catch (e) {
      refreshController?.loadComplete();
      debugLog(e);
    }
    isLoading = false;
    refreshController?.refreshCompleted();
    update();
  }
}
